<?php
set_time_limit(0);
include '../c/config.php';
$mysqli = new mysqli($dbhost, $dbuser, $dbpwd, $dbName);
 
$theday=date("Y-m-d", strtotime("-1 day"));
$theday=date("Y-m-d");

$sql="select id from `zuansu_user`  ";
$query=$mysqli->query($sql);
while ($list=$query->fetch_assoc()) {
  $zslink=$list['id'];
  $getLiuLiang=array();

  for($ji=1;$ji<4;$ji++){
 
    $sql="select count(id) as pv from `y1_puv` where zslink='".$zslink."' and ji=".$ji."  and createtime like '".$theday."%' ";
    echo "$sql";
    echo "<br />";
    $querypv=$mysqli->query($sql);
    $getData=$querypv->fetch_assoc();
    $thePv=$getData['pv'];


    $sql="select count(distinct openid) as uv from `y1_puv` where zslink='".$zslink."' and ji=".$ji."  and createtime like '".$theday."%' ";
    $queryuv=$mysqli->query($sql);
    $getData=$queryuv->fetch_assoc();
    $theUv=$getData['uv'];
    
    //var_dump($theUv);
    //echo "<br>";

    $sql="select SUM(cha) as cha from `zsu_user_time` where zslink='".$zslink."' and ji=".$ji." and statime like '".$theday."%' and endtime is NOT NULL";
    $querycha=$mysqli->query($sql);
    $getData=$querycha->fetch_assoc();
    $theCha=$getData['cha'];
    if(0 == $theCha){
      $viewTime=0;
    }else{
      $viewTime=$theCha / $thePv;
    }
    
 

    $sql="select count(id) as tui from `zsu_user_time` where zslink='".$zslink."' and ji=".$ji." and statime like '".$theday."%' and endtime is NULL";
    $querytui=$mysqli->query($sql);
    $getData=$querytui->fetch_assoc();
    $theTui=$getData['tui'];

     if(0 == $theTui){
      $viewTui=0;
     }else{
      $viewTui=$theTui / $thePv;
     }

     $getLiuLiang[$ji]=array(
      'pv' => $thePv, 
      'uv' => $theUv
    );
     
  }


  $sql="select id from `zsu_lie_tong` where zslink='".$zslink."'  and theday='".$theday."'  limit 0,1 ";
  $queryTong = $mysqli->query($sql);
  if($queryTong->num_rows>0){


  }else{
       
    $mysqli->query("INSERT INTO `zsu_lie_tong` (`id`, `zslink`, `pv1`, `uv1`, `pv2`, `uv2`, `pv3`, `uv3`, `theday`) VALUES (NULL, '".$zslink."',".$getLiuLiang[1]['pv'].", '".$getLiuLiang[1]['uv']."',".$getLiuLiang[2]['pv'].", '".$getLiuLiang[2]['uv']."',".$getLiuLiang[3]['pv'].", '".$getLiuLiang[3]['uv']."', '".$theday."')");

  }

    
}

 

 
$mysqli->close();
    
 
?>